//
//  NotifyTableViewController.m
//  MyLittleBrother
//
//  Created by speeda on 17/8/1.
//  Copyright © 2017年 speeda. All rights reserved.
//

#import "NotifyTableViewController.h"
#import <AudioToolbox/AudioToolbox.h>

@interface NotifyTableViewController () <UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *notifyTableView;
@property (nonatomic, strong) NSArray *notifyArray;

@end

@implementation NotifyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initView];
}

- (void)initView {

    self.title = @"新消息通知";
    self.notifyTableView.dataSource = self;
    self.notifyTableView.delegate = self;
    self.notifyTableView.estimatedRowHeight = 100;
    self.notifyTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.notifyTableView.rowHeight = UITableViewAutomaticDimension;
    self.notifyTableView.tableFooterView = [[UIView alloc] init];
    self.notifyTableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
}





#pragma maek -- UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 3;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *settingCell = @"settingCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:settingCell];
    
    UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
    switchView.on = YES;
    switchView.tag = indexPath.row;
    //        switchView.tintColor = [UIColor lightGrayColor];
    switchView.onTintColor = [UIColor blueColor];
    //        switchView.thumbTintColor = [UIColor blueColor];
    [switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:settingCell];
        cell.accessoryView =switchView;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.textLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16]];
        cell.detailTextLabel.numberOfLines = 0;
        cell.detailTextLabel.textColor = [UIColor darkGrayColor];
    }
    
    if (indexPath.row == 0) {
        switchView.userInteractionEnabled = NO;
        cell.textLabel.text = @"接受新消息通知";
        cell.detailTextLabel.text = @"如果你要打开或者关闭我是小哥的通知，请在iphone的“设置-通知”功能中，找到我是小哥进行修改";
    } else if (indexPath.row == 1) {
    
        cell.textLabel.text = @"声音";
        
    } else {
    
        switchView.on = NO;
        cell.textLabel.text = @"震动";
        cell.detailTextLabel.text = @"关闭之后，在应用内收到通知将不会有声音或者震动提示";
    }
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 60;
}


-(void)switchAction:(UISwitch *)switchButton
{
    BOOL isButtonOn = [switchButton isOn];
    if (switchButton.tag == 1) {
        if (isButtonOn) {
            
            AudioServicesPlaySystemSound(1007);//这个声音是是类似于QQ声音的
            
        }else {
            
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
        }
    }else if (switchButton.tag == 2) {
    
        if (isButtonOn) {
            
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
            
        }else {
            
            AudioServicesPlaySystemSound(1007);//这个声音是是类似于QQ声音的
        }
    }
    
}




@end
